import time
import services
import os


if __name__ == "__main__":
    print "about to stop webui service"
    
    try:
        web_ui_service = services.resolve_service("webui")
        web_ui_service.stop()
    except Exception as e:
        print e
   
    ''' 
    print "about to stop file crawler service"

    try:
        file_crawler_service = services.resolve_service("crawlerservice")
        file_crawler_service.stop()
    except Exception as e:
        print e



    print "about to stop data store service"
    
    try:
        data_store_service = services.resolve_service("datastoreservice")
        data_store_service.stop()
    except Exception as e:
        print e
    '''
    print "about to stop rpc service"
    
    try:
        rpc_service = services.resolve_service("rpcservice")
        rpc_service.stop()
    except Exception as e:
        print e


    rpc_server_pid_file_path = os.path.expanduser(os.path.join("~","db","rpc_server.pid"))

    rpc_server_pid_file = open(rpc_server_pid_file_path, "r")
    
    rpc_server_pid = int(rpc_server_pid_file.read())

    rpc_server_pid_file.close()

    print "About to kill RPC Server"

    os.kill(rpc_server_pid, 9)
